package com.dollar.ArtConcurrentBook.chap5;

public class Adder {
    private int count = 0;
    Mutex mutex = new Mutex();

    public int getCount() {
        return count;
    }

    public void addOne() {
        mutex.lock();
        try {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count++;
        } finally {
            mutex.unlock();
        }
    }

    public void addOne2() {
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count++;
    }
}
